package com.tangbuzhi.chm.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.tangbuzhi.chm.model.FragmentInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * http://git.oschina.net/tangbuzhi
 *
 * @author Tangbuzhi
 * @version V2.0
 * @Package com.tangbuzhi.chm.adapter
 * @Description: ${TODO}
 * @date: 2017/9/11
 */
public class TabAdapter extends FragmentPagerAdapter {
    private List<FragmentInfo> fragments = new ArrayList<>();

    public TabAdapter(FragmentManager fm) {
        super(fm);
    }

    public void addData(List<FragmentInfo> fragments) {
        if (fragments != null) {
            this.fragments = fragments;
        }
    }

    public void clear() {
        fragments.clear();
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position).getFragment();
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return fragments.get(position).getTitle();
    }
}
